﻿#include "MsgIdManager.h"

#include <qdebug.h>

ushort MsgIdManager::msgId=0;
ushort MsgIdManager::mask=0xfff;
MsgIdManager::MsgIdManager(QObject *parent) : QObject(parent)
{
}

MsgIdManager::~MsgIdManager()
{}

ushort MsgIdManager::getMsgId()
{
  return (msgId++)&mask;
}

ushort MsgIdManager::getNextMsgId(ushort currentMsgId)
{
  return (++currentMsgId)&mask;
}

bool MsgIdManager::isReceiveOldMsgId(ushort currentMsgId,ushort msgIdReceived)
{
  return currentMsgId==msgIdReceived?false:(((msgIdReceived&mask)-(currentMsgId&mask))&mask)<(mask/2)?false:true;
}
